//
//  BXBaseVC.swift
//  d11
//
//  Created by peale on 2018/7/25.
//  Copyright © 2018年 Tech_001. All rights reserved.
//

import UIKit
class BXBaseVC: UIViewController {
    
    var _loadView: UIView?
    
    override func viewDidLoad() {
        super.viewDidLoad()
//        self.navigationController?.navigationBar.topItem?.title = "";
        
        // 更改导航栏标题字体、字体大小、颜色
        let dict: NSDictionary = [NSAttributedString.Key.foregroundColor: UIColor.init("4B4B4B") ?? UIColor.black, NSAttributedString.Key.font: UIFont(name: "PingFangSC-Regular", size: 18.0)!]
        self.navigationController?.navigationBar.titleTextAttributes = dict as? [NSAttributedString.Key : Any]
        self.navigationController?.navigationBar.shadowImage = UIImage()
    }
    
    func showLoadHUD(title : NSString) -> Void {
        var msg = title
        
        if msg.isEqual(to: "") {
            msg = "读取中..."
        }
        self._loadView = UIHelper.initLoadView(self, withMessage: msg as String)
        self.view.addSubview(self._loadView!)
    }
    
    func dismissLoadHUD() -> Void {
        self._loadView?.removeFromSuperview()
    }
    
    func initLeftBarBtn() -> UIBarButtonItem {
        
        let topLogo = UIImage(named: "icon_nav_left_logo")
        let titleView = UIView()
        let topLogoView = UIImageView(image: topLogo)
        titleView.addSubview(topLogoView)
        topLogoView.contentMode = .scaleToFill
       topLogoView.frame = CGRect(x: -(137/2), y:-(35/2), width: 137, height: 35)
        return   UIBarButtonItem(customView: topLogoView)
    }
    
    func initRightBarBtn() -> UIButton {
        let rightBarBtn = UIButton(type: UIButton.ButtonType.custom)
        rightBarBtn.setImage(imageNamed("icon_nav_right_amount"), for:UIControl.State.normal)
        rightBarBtn.setTitle("0.00", for: UIControl.State.normal);
        rightBarBtn.titleLabel?.font = UIFont.systemFont(ofSize: 12);
        rightBarBtn.imageEdgeInsets = UIEdgeInsets(top: 0, left: -12, bottom: 0, right: 0);
        rightBarBtn.addTarget(self, action: #selector(self.pushWebViewTransfer), for: .touchUpInside)
        rightBarBtn.setTitleColor(UIColor.init("333333"), for: .normal)
        return rightBarBtn
    }
    
    //跳转到钱包页面-step1
    @objc func pushWebViewTransfer(){
        //主账户
//        if  GlobalInfo.isPlatformMainhtml == nil || GlobalInfo.isPlatformMainhtml != false{
//            self.pushNavigateWebView(toPath: "/walletm/transfer", "主账户",sign: true)
//        }else{
            let vc = MainAccountVC()
            vc.hidesBottomBarWhenPushed = true
            self.navigationController?.pushViewController(vc, animated: true)
 //       }
    }
    
    //跳转到web页面
    func pushNavigateWebView(toPath: String, _ title: String,sign:Bool){
       self.pushNavigateWebView(toPath: toPath, title, sign: sign, isEagleeyes: false)
    }
    
    func pushNavigateWebView(toPath: String, _ title: String,sign:Bool,isEagleeyes:Bool){
        //2018.6.4 mt 改 http 改为https
        let goNext: WebViewController = WebViewController.init()
        let url = "https://" + UserDefaults.standard.string(forKey: DefaultKey.USER_DOMAIN)! + toPath
        goNext.url = url
        goNext.title = title
        goNext.bottomOffset = 0
        goNext.signLoging=sign
        goNext.isEagleeyes = isEagleeyes
        if toPath == "/walletm/deposit" {
            goNext.isShowRefresh = false
        }
        goNext.hidesBottomBarWhenPushed = true
        self.navigationController?.pushViewController(goNext, animated: true)
        
    }
    // 设置导航栏中间图片标题
    func navigationItemTitleView() {
        self.navigationItem.titleView = UIImageView.init(image: UIImage.init(named: "navi_icon_titleLogo"))
    }
    // 设置导航栏中间标题
    func navigationItemTitleViewDefault() {
        self.navigationItem.titleView = nil
    }
    
    // 设置导航栏背景透明
    func navigationBarClear() {
        //设置导航栏背景透明
        self.navigationController?.navigationBar.setBackgroundImage(UIImage(),
                                                                    for: .default)
        self.navigationController?.navigationBar.shadowImage = UIImage()
    }
    // 设置默认导航栏背景
    func navigationBarDefault() {
        self.navigationController?.navigationBar.setBackgroundImage(nil, for: .default)
        self.navigationController?.navigationBar.shadowImage = nil
    }
    // 导航栏左边按钮
    func leftButtonActionWithImg(_ image: String) {
        let naviLeftButton = UIButton.init(type: UIButton.ButtonType.custom)
        naviLeftButton.frame = CGRect.init(x: 0, y: 0, width: 22, height: 22);
        naviLeftButton.setBackgroundImage(UIImage.init(named: image), for: UIControl.State.normal)
        naviLeftButton.setBackgroundImage(UIImage.init(named: image), for: UIControl.State.highlighted)
        naviLeftButton.addTarget(self, action: #selector(doLeftNaviAction), for: UIControl.Event.touchUpInside)
        self.navigationItem.leftBarButtonItem = UIBarButtonItem.init(customView: naviLeftButton)
    }
    // 导航栏左边按钮点击
    @objc func doLeftNaviAction() {
        self.navigationController?.popViewController(animated: true)
    }
    
}
